IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[cms_sp_EntityRevisionSave]') AND type in (N'P', N'PC'))
	DROP PROCEDURE [dbo].[cms_sp_EntityRevisionSave]
GO
create procedure [dbo].[cms_sp_EntityRevisionSave]
@EntityId int,
@EntityTypeParameter nvarchar(400),
@IsLatestRevision bit = null,
@IsLatestCompletedRevision bit = null,
@WorkflowId uniqueidentifier = null
as
declare @CurrentLatestRevisionStatus bit
declare @CurrentLatestCompletedRevisionStatus bit
select 
	@CurrentLatestRevisionStatus = isnull(@IsLatestRevision, IsLatestRevision),
	@CurrentLatestCompletedRevisionStatus = isnull(@IsLatestCompletedRevision, IsLatestCompletedRevision)
from dbo.EntityRevisions
where EntityId = @EntityId and 
	EntityTypeParameter = @EntityTypeParameter
update dbo.EntityRevisions
set IsLatestRevision = @CurrentLatestRevisionStatus,
	IsLatestCompletedRevision = @CurrentLatestCompletedRevisionStatus,
	IsPublished = @CurrentLatestCompletedRevisionStatus,
	WorkflowId = @WorkflowId
where EntityId = @EntityId and 
	EntityTypeParameter = @EntityTypeParameter


GO

